from fastapi import FastAPI
from app.api.router import router as api_router
from contextlib import asynccontextmanager
from app.core.db import create_db_and_tables


@asynccontextmanager
async def lifespan(app: FastAPI):
    # 在应用启动时执行的代码
    print("应用启动")
    create_db_and_tables()
    yield
    # 在应用关闭时执行的代码
    print("应用关闭")


app = FastAPI(lifespan=lifespan)

app.include_router(api_router)
